dir=$(dirname $0)
cd $dir && cd ..

OUTPUT="output"
CACHE=".f2e_cache"
NODE_VERSION="node-v20.10.0-linux-x64"
VERSION=`node -e "console.log(require('./package.json').version)"`

if [ ! -d $OUTPUT ]
then
    sh ./build.sh
fi

if [ ! -d $CACHE ]
then
    mkdir $CACHE
fi

cd $CACHE

if [ ! -f "node" ]
then
    rm -rf $NODE_VERSION"*"
    curl "https://nodejs.org/dist/v20.10.0/"$NODE_VERSION".tar.xz" -o $NODE_VERSION".tar.xz"
    tar -xf $NODE_VERSION".tar.xz"
    cp $NODE_VERSION"/bin/node" ./
fi

if [ ! -f "node" ]
then
    echo "node download error"
    exit 1
fi

cd ..
docker build -f script/node.Dockerfile -t "f2e-server/react-app:"$VERSION .
